/*
 * Copyright (c) 2006, 2022, webrx.cn All rights reserved.
 *
 */
package cn.rand;

import java.awt.*;
import java.util.Random;
import java.util.UUID;

/**
 * <p>Project: app2022 - Rand1
 * <p>Powered by webrx On 2022-01-06 10:27:35
 *
* @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Rand1 {
    public static void main(String[] args) {
        System.out.println(Math.PI);
        //Math.random() 返回0-1之间的随机小数（double）
        System.out.println(Math.random());
        System.out.println(Math.random());
        System.out.println(Math.random());

        var rand = new Random();
        System.out.println(rand.nextBoolean());
        System.out.println(rand.nextBoolean());
        System.out.println(rand.nextBoolean());

        //0 1 2 随机整数
        //System.out.println(rand.nextInt(3));
        //1-100 的随机整数
        int num = rand.nextInt(100) + 1;
        if (num <= 30) {
            System.out.println("恭喜您(" + num + ")");
        } else {
            System.out.println(num);
        }

        //随机颜色
        //Color c = new Color(255, 0, 0);//#ff0000

        //Color c = new Color(0x33, 0xff, 0x00);//#ff0000
        int rr = rand.nextInt(255);
        int gg = rand.nextInt(255);
        int bb = rand.nextInt(255);
        Color c = new Color(rr, gg, bb);

        //随机范围 15-20
        for (int i = 0; i < 10; i++) {
            int range = rand.nextInt(20 - 15 + 1) + 15;
            System.out.println(range);
        }

        for (int i = 0; i < 5; i++) {
            System.out.println(rand.nextDouble());
        }

        String letter = "abcdefghjkmnpqrstuvwxyABCDEFGHIJKLMNPQRSTUVWXY3456789";
        StringBuilder sbu = new StringBuilder();
        for (int i = 0; i < 4; i++) {
            sbu.append(letter.charAt(rand.nextInt(letter.length())));
        }
        System.out.println("密码：" + sbu);

        //全球唯一 随机字符串
        UUID u = UUID.randomUUID();
        //36位
        System.out.println(u.toString().length());

        //7aa4be70-c0d4-40b8-aa27-7d71cd197a9a
        //be1b4751-9686-4dd4-8c1f-9c900a24ab5b

        //SnowFlake long id

    }
}
